#include "TaskScheduler.h"

#include "Task.h"
#include "BuildEventTimeline.h"
#include "BuildUnitManager.h"
#include "..\Util.h"

namespace BroodWar
{
	namespace Addon
	{
		TaskScheduler::TaskScheduler(BWSAL::TaskScheduler* scheduler)
		{
			instance = scheduler;
		}

		TaskScheduler::~TaskScheduler()
		{
			BWSAL::TaskScheduler::destroy();
		}

		TaskScheduler::!TaskScheduler()
		{
			BWSAL::TaskScheduler::destroy();
		}

		void TaskScheduler::Create(IBuildEventTimeline^ timeline, IBuildUnitManager^ buildUnitManager)
		{
			BuildEventTimeline^ evtTimeline = DirectCast<BuildEventTimeline^>(timeline);
			BuildUnitManager^ manager = DirectCast<BuildUnitManager^>(buildUnitManager);
			BWSAL::TaskScheduler::destroy();
			s_instance = gcnew TaskScheduler(BWSAL::TaskScheduler::create(evtTimeline->instance, manager->instance));
		}
		
		TaskScheduler^ TaskScheduler::Instance::get()
		{
			return s_instance;
		}

		TaskPlan^ TaskScheduler::ScheduleTask(Task^ task)
		{
			return ConvertTaskPlan(instance->scheduleTask(ConvertTask(task)));
		}
		
		bool TaskScheduler::FinalizeSchedule()
		{
			return instance->finalizeSchedule();
		}
		
		int TaskScheduler::InsufficientTypes::get()
		{
			return instance->getInsufficientTypes();
		}
		
		int TaskScheduler::SupplyBlockTime::get()
		{
			return instance->getSupplyBlockTime();
		}
		
		void TaskScheduler::ResetSupplyBlockTime()
		{
			instance->resetSupplyBlockTime();
		}
		
		int TaskScheduler::LastMineralBlockTime::get()
		{
			return instance->getLastMineralBlockTime();
		}
		
		void TaskScheduler::ResetLastMineralBlockTime()
		{
			instance->resetLastMineralBlockTime();
		}
		
		int TaskScheduler::LastGasBlockTime::get()
		{
			return instance->getLastGasBlockTime();
		}
		
		void TaskScheduler::ResetLastGasBlockTime()
		{
			instance->resetLastGasBlockTime();
		}
		
		BuildEventTimeline^ TaskScheduler::Timeline::get()
		{
			return gcnew BuildEventTimeline(instance->getTimeline());
		}
	}
}
